package com.neuedu.singleton;

import java.util.Objects;

public class Student {
    //成员变量
    private String stuName;
    private String stuSex;
    private int stuAge;

    public Student(String stuName, String stuSex, int stuAge) {
        this.stuName = stuName;
        this.stuSex = stuSex;
        this.stuAge = stuAge;
    }

    //行为方法
    public void doStuding(){
        System.out.println("I am studing....");
    }
    //显示写出默认的构造方法
    public Student(){

    }
    public boolean equals(Object stu){
        // == 判定成立，则内容一定相同
        if (this == stu){
            return true;
        }
        //判定内容是否相等
        if (stu instanceof Student){
            //强制类型转换
            Student student=(Student) stu;
            //按业务逻辑进行内容的相等判定
            //规定：只有姓名、年龄、性别同时相同才相等
            if (this.stuName !=null && this.stuName.equals(student.stuName)
                    &&
                this.stuSex !=null && this.stuSex.equals(student.stuSex)
                   &&
                    this.stuAge == student.stuAge){
                return true;
            }
        }
        //判定结果不相等
        return false;
    }

   /* @Override
    public boolean equals(Object o) {
        //== 判定成立，则内容一定相同
        if (this == o) return true;
        //比较的对象如果为null，或者二者不是同一类型，则返回false
        if (o == null || getClass() != o.getClass()) return false;
        //按业务逻辑进行内容的相等判定
        Student student = (Student) o;
        return Objects.equals(stuName, student.stuName) &&
                Objects.equals(stuSex, student.stuSex) &&
                Objects.equals(stuAge, student.stuAge);
    }

    @Override
    public int hashCode() {

        return Objects.hash(stuName, stuSex, stuAge);
    }*/
}
